import type { AddressItem, AddressResultItem } from '@/types/address'
import request from '@/utils/request/request'
/**
 * 获取用户地址列表
 * @returns
 */
export const getAddressAPI = () => {
  return request<AddressResultItem[]>({
    method: 'GET',
    url: '/addressBook/list',
  })
}
/**
 * 查询默认地址
 * @returns
 */
export const getDefaultAddressAPI = () => {
  return request({
    method: 'GET',
    url: '/addressBook/default',
  })
}
/**
 * 新增收货地址
 * @param data
 * @returns
 */
export const addAddressAPI = (data: AddressItem) => {
  return request({
    method: 'POST',
    url: '/addressBook',
    data: data,
  })
}
/**
 * 根据id获取地址详情
 * @param id
 * @returns
 */
export const getAddressDetailAPI = (id: number) => {
  return request<AddressResultItem>({
    method: 'GET',
    url: `/addressBook/${id}`,
  })
}
/**
 * 根据id修改地址详情
 * @param id
 * @returns
 */
export const putAddressDetailAPI = (data: AddressItem) => {
  return request({
    method: 'PUT',
    url: '/addressBook',
    data: data,
  })
}
/**
 * 根据id删除地址
 * @param id
 * @returns
 */
export const deleteAddressAPI = (id: number) => {
  return request({
    method: 'DELETE',
    url: '/addressBook',
    params: { id },
  })
}
/**
 * 设置默认地址
 * @param id
 * @returns
 */
export const putDefaultAddressAPI = (id: number) => {
  return request({
    method: 'PUT',
    url: '/addressBook/default',
    data: id,
  })
}
